﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
using System.Globalization;
using System.Windows.Media;

namespace ImageProcessing
{
    public class BoolToVisibility : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool invertMode;
            if (!(parameter != null && bool.TryParse(parameter.ToString(), out invertMode)))
                invertMode = false;
            bool is_visible = (bool)value ^ invertMode;
            if (is_visible)
                return Visibility.Visible;
            else
                return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool invertMode;
            if (!(parameter != null && bool.TryParse(parameter.ToString(), out invertMode)))
                invertMode = false;
            return ((Visibility)value == Visibility.Visible) ^ invertMode;
        }
    }

    public class ByteStringToBrush : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            byte checkValue;
            if (!(value != null && byte.TryParse(value.ToString(), out checkValue))) return Brushes.Red;
            return Brushes.Black;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        { throw new NotImplementedException(); }
    }

    public class UDoubleStringToBrush : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            double checkValue;
            if (!(value != null && double.TryParse(value.ToString(), out checkValue) && checkValue > 0)) return Brushes.Red;
            return Brushes.Black;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        { throw new NotImplementedException(); }
    }

    
}
